###################################################################
############### Module 6, Basics of data wrangling ################
###################################################################
## Lesson 14, Part 2: Dealing with dates (visualizing)


# First load the tidyverse and lubridate packages and the dataframe from 
# where we left off in the last part:
library(tidyverse)
library(lubridate)
ff_data_summ <- read_csv("data/ff_data_summ.csv")

###################################
##### VISUALIZATION
boxplot(day_mean ~ species, data=ff_data_summ)

seq_along(ff_data_summ$species)

plot(seq_along(species) ~ day_mean, data=ff_data_summ)

spp_names <- ff_data_summ$species


par(mai=c(1,2, 0.5, 0.5))
plot(seq_along(species) ~ day_mean, data=ff_data_summ, ylab="",
     yaxt="n", pch=16, col="tomato2", cex=1.5,
     xlab="Julian Day of First Flower", xlim=c(60,180))
axis(side=2, at=seq_along(spp_names), labels = spp_names, las = 2)

arrows(y0 = seq_along(spp_names), y1 = seq_along(spp_names), 
       x0 = ff_data_summ$day_mean, x1 = ff_data_summ$day_latest,
       col="tomato2", lwd=2, angle=90, length=0.1)

arrows(y0 = seq_along(spp_names), y1 = seq_along(spp_names), 
       x0 = ff_data_summ$day_mean, x1 = ff_data_summ$day_earliest,
       col="tomato2", lwd=2, angle=90, length=0.1)

ff_data_summ_sorted <- arrange(ff_data_summ, desc(day_mean))

spp_names_sorted <- ff_data_summ_sorted$species

par(mai=c(1,2, 0.5, 0.5))
plot(seq_along(species) ~ day_mean_d, data=ff_data_summ_sorted, ylab="",
     yaxt="n", pch=16, col="tomato2", cex=1.5,
     xlab="Date of First Flower", xlim=c(dmy("01/03/1900"),dmy("01/07/1900")))
axis(side=2, at=seq_along(spp_names_sorted), labels = spp_names_sorted, las = 2)

arrows(y0 = seq_along(spp_names_sorted), y1 = seq_along(spp_names_sorted), 
       x0 = ff_data_summ_sorted$day_mean_d, x1 = ff_data_summ_sorted$latest_d,
       col="tomato2", lwd=2, angle=90, length=0.1)

arrows(y0 = seq_along(spp_names_sorted), y1 = seq_along(spp_names_sorted), 
       x0 = ff_data_summ_sorted$day_mean_d, x1 = ff_data_summ_sorted$earliest_d,
       col="tomato2", lwd=2, angle=90, length=0.1)

###################################
##### SUMMARY
# - Visualizing our data and creating custom range bars


